import {
  createReactive
} from "./reactive";
import {
  isObject
} from "./utils";

const get = createGetter();
const set = createSetter();

function createGetter() {
  //返回proxy函数
  //handler.get() -> 
  /**
   * var p = new Proxy(target, {
   *   get: function(target, property, receiver){
   *     
   *   }
   * });
   */
  return function (target, key, receiver) {
    const res = Reflect.get(target, key, receiver);

    if (isObject(res)) {
      return createReactive(res);
    }

    return res;
  }
}

function createSetter() {
  return function (target, key, value, receiver) {
    return Reflect(target, key, value, receiver);
  }
}

export const proxyHandler = {
  get,
  set
};